import {GetDetail,addToCart} from '@/API/index'
import {get_uuid} from '@/utils/uuid_cookie'
export default {
    namespaced:true,
    actions:{
       async get_detail({commit},id){
            let getid = await GetDetail(id);
            if (getid.data.code==200) {
                commit('GET_DETAIL',getid.data.data)
            }
        },
        async getToCart({commit},sku){
            let cart =  await addToCart(sku[0],sku[1]);
            if (cart.data.code==200) {
                return 'OK'
            }else{
                return Promise.reject(new Error('faile'))
            }
        }
    },
    mutations:{
        GET_DETAIL(minstore,value){
            minstore.getDetail = value
        },
    },
    state:{
        getDetail:{},
        cookie:get_uuid()
    },
    getters:{
        categoryView(store){
            return store.getDetail.categoryView || {}
        },
        skuInfo(store){
            return store.getDetail.skuInfo || {}
        },
        spuSaleAttrList(store){
            return store.getDetail.spuSaleAttrList || []
        }
    }
}